Pressidian
花园入口
笔记
项目
关于
实验室
GitHub
花园入口
笔记
项目
关于
实验室
GitHub

KNOWLEDGE PATHS

笔记库
当前位置
笔记库/前端/三件套/样式/CSS/MDN文档/1 基础样式/4 层叠、优先级与继承

Test your skills: The Cascade

11 分钟阅读 · Note

目录树 578 篇

                  • 层叠、优先级与继承
                  • Challenge: Fixing blog page styles
                  • Test your skills: The Cascade
          • tailwindCSS
      • 前端技术栈
    • 笔记目录
    • CLAUDE.md
    • Vue 组件与 Render 函数

关联笔记 6

↗层叠、优先级与继承同一路径↗Challenge: Fixing blog page styles同一路径↗背景与边框共同主题↗测试你的技能:CSS 样式基础共同主题↗调试 CSS共同主题↗关系选择器共同主题
  • Test your skills: The Cascade

Test your skills: The Cascade

  • Previous
  • Overview: CSS styling basics
  • Next

The aim of this skill test is to help you assess whether you understand universal property values for controlling inheritance in CSS.

Note: To get help, read our Test your skills usage guide. You can also reach out to us using one of our communication channels.

Cascade 1

In this task, we want you to use one of the special values we looked at in the controlling inheritance section.

To complete the task, write a declaration in a new rule that will reset the background color back to white, without using an actual color value.

The starting point of the task looks like this:

Play

Here's the underlying code for this starting point:

htmlCopyPlay

<div class="container" id="outer">
  <div class="container" id="inner">
    <ul>
      <li class="nav"><a href="#">One</a></li>
      <li class="nav"><a href="#">Two</a></li>
    </ul>
  </div>
</div>

cssCopyPlay

#outer div ul .nav a {
  background-color: powderblue;
  padding: 5px;
  display: inline-block;
  margin-bottom: 10px;
}

div div li a {
  color: rebeccapurple;
}

The updated styling should look like this:

Play

Click here to show the solution

One possible solution is as follows:

There are two things you need to do in this task. First, write a selector for the a element which is more specific than the selector used to turn the background powderblue. In this solution, this is achieved by using the id selector, which has very high specificity.

Then you need to remember there are special keyword values for all properties. In this case, using inherit sets the background color back to be the same as its parent element.

Cascade 2

To complete this task, manipulate the cascade layer order to color the links rebeccapurple. No editing the lightgreen declaration!

This task is a stretch goal — it requires knowledge of cascade layers, which we didn't cover in the Handling conflicts article. You can find the information you need to attempt this task at Cascade layers > Determining the precedence based on the order of layers.

The starting point of the task looks like this:

Play

Here's the underlying code for this starting point:

htmlCopyPlay

<div class="container" id="outer">
  <div class="container" id="inner">
    <ul>
      <li class="nav"><a href="#">One</a></li>
      <li class="nav"><a href="#">Two</a></li>
    </ul>
  </div>
</div>

cssCopyPlay

@layer yellow, purple, green;

@layer yellow {
  #outer div ul .nav a {
    padding: 5px;
    display: inline-block;
    margin-bottom: 10px;
  }
}
@layer purple {
  div div li a {
    color: rebeccapurple;
  }
}
@layer green {
  a {
    color: lightgreen;
  }
}

The updated styling should look like this:

Play

Click here to show the solution

One possible solution is as follows:

There is one thing you need to do in this task: change the order of precedence so the declaration for the desired color is in the last declared layer, which is what this solution shows.

You need to remember that unlayered normal styles take precedence over layered normal styles. But, if all styles are within layers — as in the case of this task — styles in later declared layers take precedence over styles declared in earlier layers. Moving the purple layer to the end means it has precedence over the green and yellow layers.

  • Previous
  • Overview: CSS styling basics
  • Next

Help improve MDN

Was this page helpful to you?

YesNo

Learn how to contribute

This page was last modified on Feb 3, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content

Filter sidebar

  1. Learn web development

  2. MDN curriculum

  3. Getting started modules

  4. Environment setup

  5. Your first website

  6. Web standards

  7. Soft skills

  8. Core modules

  9. Structuring content with HTML

  10. CSS styling basics

    1. What is CSS?
    2. CSS getting started
    3. Challenge: Biography page
    4. Basic selectors
    5. Attribute selectors
    6. Pseudo-classes and elements
    7. Combinators
    8. Test: Selectors
    9. Box model
    10. Test: Box model
    11. Handling conflicts
    12. Test: Cascade
    13. Challenge: Fixing blog styles
    14. Values and units
    15. Test: Values and units
    16. Sizing
    17. Test: Sizing
    18. Backgrounds and borders
    19. Test: Backgrounds and borders
    20. Overflow
    21. Test: Overflow
    22. Challenge: Sizing and decorating
    23. Images, media, forms
    24. Test: Images and forms
    25. Styling tables
    26. Challenge: Styling color scheme search
    27. Debugging CSS
    28. Test: Styling basics tests index
    29. Additional tutorials
  11. CSS text styling

  12. CSS layout

  13. Dynamic scripting with JavaScript

  14. JavaScript frameworks and libraries

  15. Accessibility

  16. Design for developers

  17. Version control

  18. Extension modules

  19. Advanced JavaScript objects

  20. Client-side web APIs

  21. Asynchronous JavaScript

  22. Web forms

  23. Understanding client-side tools

  24. Server-side websites

  25. Web performance

  26. Testing

  27. Further resources

  28. How to solve common problems

  29. About

  30. Resources for educators

  31. Changelog

MongoDB AtlasAd

Your blueprint for a better internet.

MDN

  • About
  • Blog
  • Mozilla careers
  • Advertise with us
  • MDN Plus
  • Product help

Contribute

  • MDN Community
  • Community resources
  • Writing guidelines
  • MDN Discord
  • MDN on GitHub

Developers

  • Web technologies
  • Learn web development
  • Guides
  • Tutorials
  • Glossary
  • Hacks blog

  • Website Privacy Notice
  • Telemetry Settings
  • Legal
  • Community Participation Guidelines

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.